package com.lsk.internalcommon.DTO;

import com.lsk.internalcommon.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class ResponseResult <T>{

    private int code;
    private String message;
    private T data;

    /**
     * 响应成功的方法
     * @return
     */
    public static <T>ResponseResult success(){
        return  new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue());
    }

    /**
     * 响应成功的方法
     * @param data
     * @return
     * @param <T>
     */
    public static <T>ResponseResult success(T data){
        return  new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue()).setData(data);
    }

    /**
     * 响应失败的方法 自定义错误信息提示
     * @param data
     * @return
     */
    public static ResponseResult fail(int code,String message,String data){
        return new ResponseResult().setCode(code).setMessage(message).setData(data);
    }

    public static ResponseResult fail(){
        return new ResponseResult().setCode(CommonStatusEnum.FAIL.getCode()).setMessage(CommonStatusEnum.FAIL.getValue());
    }

    public static <T>ResponseResult fail(T data){
        return new ResponseResult().setData(data);
    }


    public static <T>ResponseResult fail(int code,String message){
        return new ResponseResult().setCode(code).setMessage(message);
    }
}
